package com.engr.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.engr.consts.AuthConsts;
import com.engr.consts.SysConsts;
import com.engr.exception.ExceptionUtils;
import com.engr.web.HttpContext;

import java.util.Date;

/**
 * @program: train-project
 * @description: controller基类
 * @author: lyx
 * @create: 2018-10-06
 **/
public abstract class BaseController {

    protected static final String TOKEN_HEADER = AuthConsts.TOKEN_HEADER;
    /**
     * request
     * @return
     * @author :kezhan
     * @since : 2018年6月20日
     */
    public HttpServletRequest request() {
        HttpServletRequest request = httpContext().getRequest();
        if (request == null) {
            ExceptionUtils.throwBaseException("系统异常");
        }
        return request;
    }

    /**
     * response
     * @return
     * @author :kezhan
     * @since : 2018年6月20日
     */
    public HttpServletResponse response() {
        HttpServletResponse response = httpContext().getResponse();
        if (response == null) {
            ExceptionUtils.throwBaseException("系统异常");
        }
        return response;
    }

    /**
     * 获取上下文信息
     * @return
     * @author :kezhan
     * @since : 2018年6月20日
     */
    public HttpContext httpContext() {
        HttpContext httpContext = HttpContext.current();
        if (httpContext == null) {
            ExceptionUtils.throwBaseException("系统异常");
        }
        return httpContext;
    }
}
